<%@ page contentType="text/html;charset=utf8" %> 
<% 
java.sql.Connection conn=null; 
java.sql.PreparedStatement preparedStmt=null; //语句对象 
java.sql.ResultSet sqlRst=null; //结果集对象 
try{
Class.forName("com.mysql.jdbc.Driver");
conn= java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/bookstore?zeroDateTimeBehavior=convertToNull","root","1234"); 
preparedStmt =conn.prepareStatement("select cust_id,cust_name,cust_realName,cust_address from bs_customer where cust_name like ? ");
//设置参数
request.setCharacterEncoding("UTF-8");
String parm= request.getParameter("parm");
preparedStmt.setString(1,"%"+parm+"%");
//执行Sql语句 
sqlRst=preparedStmt.executeQuery (); 
%>
<center>顾客信息表</center>
<table border="1" width="100%" bordercolorlight="#CC99FF" cellpadding="2" bordercolordark="#FFFFFF" cellspacing="0"> 
<tr> 
  <td align="center">&nbsp;ID</td> 
   <td align="center">地址</td> 
   <td align="center">姓名</td> 
  </tr> 
<% while (sqlRst.next()) { //取得下一条记录
String name=new String(sqlRst.getString("cust_name")+"===>");
name+=new String(sqlRst.getString("cust_realName"));
 %> 
<tr><!--显示记录--> 
  <td><%=sqlRst.getString("cust_id")%></td> 
  <td><%=new String(sqlRst.getString("cust_address"))%></td> 
  <td><%=name%></td>
   </tr> 
<% } %> 
</table>
<%
 } catch (java.sql.SQLException e){
    out.println(e.toString());
}finally{
//关闭结果集对象
    if(sqlRst!=null)try{sqlRst.close(); } catch(java.sql.SQLException e1){
        out.println(e1.toString());
    }finally{
        try{
//关闭语句对象
            if(preparedStmt!=null)preparedStmt.close();
        }catch(java.sql.SQLException e2){
            out.println(e2.toString());
        }finally{
            try{
//关闭数据库连接
                if(conn!=null)conn.close();
            }catch(java.sql.SQLException e3){
                out.println(e3.toString());
            }
        }
    }
}
%>

